<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>后台首页 - 类别管理</title>
		<meta name="keywords" content="" />
		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<!-- basic styles -->
		<link href="__STATIC__/assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__STATIC__/assets/css/font-awesome.min.css" />
		<link rel="stylesheet" href="__STATIC__/font-awesome-4.7.0/css/font-awesome.min.css" />

		<!--[if IE 7]>
		  <link rel="stylesheet" href="__STATIC__/assets/css/font-awesome-ie7.min.css" />
		<![endif]-->

		<!-- page specific plugin styles -->

		<!-- fonts -->

		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

		<!-- ace styles -->

		<link rel="stylesheet" href="__STATIC__/assets/css/ace.min.css" />
		<link rel="stylesheet" href="__STATIC__/assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="__STATIC__/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="__STATIC__/css/public.css" />
		<link rel="stylesheet" href="__STATIC__/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">

		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="__STATIC__/assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->

		<script src="__STATIC__/assets/js/ace-extra.min.js"></script>

		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

		<!--[if lt IE 9]>
		<script src="__STATIC__/assets/js/html5shiv.js"></script>
		<script src="__STATIC__/assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>

		{include file="public/header"}

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				{include file="public/sidebar"}

				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="#">首页</a>
							</li>
							<li class="active"><a href="{:url('index')}">类别管理</a></li>
							<li class="active">类别编辑</li>
						</ul><!-- .breadcrumb -->

					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>
								类别编辑
							</h1>
						</div><!-- /.page-header -->

						<div class="alert alert-block alert-success">
							<button type="button" class="close" data-dismiss="alert">
								<i class="icon-remove"></i>
							</button>

							<i class="fa fa-hand-o-right fa-lg red" aria-hidden="true"></i>
							操作说明：前台首页商品类别的增删改查.
						</div>

						<article class="cl pd-20">
							<table class="table">
								<tr>
									<td width="200" class="va-t"><ul id="treeDemo" class="ztree"></ul></td>
									<td class="va-t">
										<div class="pd-20">
										  <form action="" method="post" class="form form-horizontal" id="form-user-add">
										    <div class="row cl">
										      <label class="form-label">当前类别ID：<span class="c-green" id="cate_id"></span><span id="cate_name"></span></label>
										      <div class="formControls col-5">
										        <input type="text" class="input-text" value="" placeholder="" id="cate-name" name="name">
										      </div>
										      <div class="col-5"> </div>
										    </div>
										    <input type="hidden" id="cate-id" name="mid" value="" />
										    <div class="row cl">
										      <div class="col-9 col-offset-2" style="margin:10px 0;" >
										        <input class="btn btn-primary noborder" type="button" id="modify" name="modify" value="&nbsp;&nbsp;修改&nbsp;&nbsp;">
										        <input class="btn btn-primary noborder" type="button" id="delete" name="delete" value="&nbsp;&nbsp;删除&nbsp;&nbsp;">
										      </div>
										    </div>
										  </form>
										  <form action="" method="post" class="form form-horizontal" id="form-user-add">
										    <div class="row cl">
										      <label class="form-label" style="text-align:left;">添加类别：<span class="c-green" id="cate_id"></span><span id="cate_name"></span></label>
										      <div class="formControls col-5">
										        <input type="text" class="input-text"  value="" placeholder="" id="cate-sname"  name="name">
										      </div>
										      <div class="col-5"> </div>
										    </div>
										    <input type="hidden" id="cate-id2" name="aid" value="" />
										    <div class="row cl">
										      <div class="col-9 col-offset-2" style="margin:10px 0;">
										        <input class="btn btn-primary noborder" type="button" id="add" name="add" value="&nbsp;&nbsp;添加&nbsp;&nbsp;">
										      </div>
										    </div>
										  </form>
										</div>
									</td>
								</tr>
							</table>
						</article>

					</div><!-- /.page-content -->
				</div><!-- /.main-content -->

			</div><!-- /.main-container-inner -->

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="icon-double-angle-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->

		<script src="__STATIC__/assets/js/jquery-2.0.3.min.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
<script src="__STATIC__/assets/js/jquery-2.0.3.min.js"></script>
<![endif]-->

		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='__STATIC__/assets/js/jquery-2.0.3.min.js'>"+"<"+"script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='__STATIC__/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
</script>
<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='__STATIC__/assets/js/jquery.mobile.custom.min.js'>"+"<"+"script>");
		</script>
		<script src="__STATIC__/assets/js/bootstrap.min.js"></script>
		<script src="__STATIC__/assets/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<!--[if lte IE 8]>
		  <script src="__STATIC__/assets/js/excanvas.min.js"></script>
		<![endif]-->

		<script src="__STATIC__/assets/js/jquery-ui-1.10.3.custom.min.js"></script>

		<!-- ace scripts -->

		<script src="__STATIC__/assets/js/ace-elements.min.js"></script>
		<script src="__STATIC__/assets/js/ace.min.js"></script>
		<script src="__STATIC__/layui-v2.2.45/layui.all.js"></script>
		<script type="text/javascript" src="__STATIC__/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>

		<!-- inline scripts related to this page -->

		<script type="text/javascript">
			var setting = {
				view: {
					dblClickExpand: true,
					showLine: false,
					selectedMulti: false
				},
				data: {
					simpleData: {
						enable:true,
						idKey: "id",
						pIdKey: "pid",
						rootPId: ""
					}
				},
				callback: {
					beforeClick: function(treeId, treeNode) {
						var zTree = $.fn.zTree.getZTreeObj("tree");
						demoIframe.attr("src",treeNode.file + ".html");
					},
					onClick: function (event, treeId, treeNode, clickFlag) {
								selectNode(treeNode);
						    }
				}
			};

			var zNodes =[
				{$allcate}
			];


			//点击类别名称获取信息
			var selectNode = function (treeNode) {
				selectTreeNode = treeNode;
				$("#cate_name").html(selectTreeNode == null ? "" : selectTreeNode.name);
				$("#cate_id").html(selectTreeNode == null ? "" : "【" + selectTreeNode.id + "】");
				$("#cate-name").val(selectTreeNode == null ? "" :  selectTreeNode.name);
				$("#cate-id").val(selectTreeNode == null ? "" :  selectTreeNode.id);
				$("#cate-id2").val(selectTreeNode == null ? "" :  selectTreeNode.id);
				if (selectTreeNode != null) {

				    var path = selectTreeNode.name;

				    var parentNode = selectTreeNode.getParentNode();

				    while (parentNode != null) {
					path = parentNode.name + "<span class='red'>－</span>" + path;
					parentNode = parentNode.getParentNode();
				    }

				    $("#lblPath").html(path);
				    $("#btnDelete").show();
				    $("#btnUp").show();
				    $("#btnDown").show();
				} else {
				    $("#lblPath").html("");
				    $("#btnDelete").hide();
				    $("#btnUp").hide();
				    $("#btnDown").hide();
				}
			}

			var code;

			function showCode(str) {
				if (!code) code = $("#code");
				code.empty();
				code.append("<li>"+str+"</li>");
			}

			/*验证表单*/
			$('#modify').click(function(){
				if($('#cate-id').val() == ''){
					alert('请选择要修改的类别');
					return false;
				}
				$.ajax({
					type:'POST',
					url:'category/edit',
					data:{
						name:$('#cate-name').val(),
						mid:$('#cate-id').val()
					},
					success:function(msg){
						if(msg=='succ'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别修改成功！',{icon:6,time:1500});
						}else if(msg=='error'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别修改失败！',{icon:5,time:1500});
						}
					}
				});
			});

			$('#delete').click(function(){
				if($('#cate-id').val() == ''){
					layer.msg('请选择要删除的类别!',{icon:2,time:1500});
					return false;
				}
				$.ajax({
					type:'POST',
					url:'{:url("category/delete")}',
					data:{
						name:$('#cate-name').val(),
						mid:$('#cate-id').val()
					},
					success:function(msg){
						if(msg=='succ'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别删除成功！',{icon:6,time:1500});
						}else if(msg=='error'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别删除失败！',{icon:5,time:1500});
						} else {
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('请先删除子类别！',{icon:6,time:1500});
						}
					}
				});
			});

			$('#add').click(function(){
				if($('#cate-sname').val() == ''){
					layer.msg('请填写要添加的类别名称!',{icon:2,time:1500});
					return false;
				}
				$.ajax({
					type:'POST',
					url:'{:url("category/cateAdd")}',
					data:{
						name:$('#cate-sname').val(),
						aid:$('#cate-id2').val()
					},
					success:function(msg){
						if(msg=='succ'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别修改成功！',{icon:6,time:1500});
						}else if(msg=='error'){
							setTimeout(function(){
								parent.location.reload();
							},1900);
							layer.msg('类别修改失败！',{icon:5,time:1500});
						}
					}
				});
			});

			$(function(){
				var t = $("#treeDemo");
				t = $.fn.zTree.init(t, setting, zNodes);
				demoIframe = $("#testIframe");
				demoIframe.bind("load", loadReady);
				var zTree = $.fn.zTree.getZTreeObj("tree");
			});
		</script>
	<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>
</body>
</html>

